<template>
  <div class="app-container home">
    <el-row :gutter="20">
      <el-col :span="24">
        <el-card class="update-log">
          <template v-slot:header>
            <div style="display:flex;justify-content: space-between;align-items: center;">
              <div style="flex:1">办证统计</div>
              <div>
                <el-date-picker
                :clearable="false"
                v-model="timeEveryDay"
                type="daterange"
                @change="getmanagerecordcounteveryday"
                value-format="YYYY-MM-DD"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
              </div>
            </div>
          </template>
          <div id="banzhengtongji">

          </div>
        </el-card>
      </el-col>
      
    </el-row>
  </div>
</template>

<script setup name="Index">
const version = ref('3.8.9');
import { managerecordcounteveryday } from "@/api/manage/record";
import dayjs from "dayjs";
let timeEveryDay=ref([dayjs().subtract(6,"day").format("YYYY-MM-DD"),dayjs().format("YYYY-MM-DD")])
let chartDom = null
let myChart = null
let allDates = [];
let option = {
  grid: {
    left: '1%',
    right: '1%',
    bottom: '3%',
    containLabel: true
  },

  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross',
      label: {
        backgroundColor: '#6a7985'
      }
    }
  },
  
  xAxis: {
    type: 'category',
    data: []
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [],
      type: 'line',
      label: {
        show: true,
        position: 'top'
      },
    }
  ]
};

function getmanagerecordcounteveryday(){
  allDates=[]
  let startDate = dayjs(timeEveryDay.value[0]);
  let  endDate = dayjs(timeEveryDay.value[1])
  let currentDate = startDate.clone(); // 使用克隆以避免修改原始日期对象

  while (currentDate.isBefore(endDate)) {
      allDates.push({
        time:currentDate.format('YYYY-MM-DD'),
        count:0
      }); 
      currentDate = currentDate.add(1, 'day'); // 增加一天
  }

  allDates.push({
    time:endDate.format('YYYY-MM-DD'),
    count:0
  }); // 添加结束日期

  managerecordcounteveryday({
    startTime:timeEveryDay.value[0],
    endTime:dayjs(timeEveryDay.value[1]).add(1, 'day').format('YYYY-MM-DD')
  }).then(res => {
    
    for(let i=0;i<allDates.length;i++){
      for(let j=0;j<res.data.length;j++){
        if(allDates[i].time==res.data[j].time){
          allDates[i].count=res.data[j].count
        }
      }
    }
    option.xAxis.data=allDates.map(item=>{
      return item.time
    })
    option.series[0].data=allDates.map(item=>{
      return item.count
    })
    myChart.setOption(option);
    
  });
}

onMounted(()=>{

  getmanagerecordcounteveryday()
 
  chartDom = document.getElementById('banzhengtongji');
  myChart = window.echarts.init(chartDom);
  
})
function goTarget(url) {
  window.open(url, '__blank')
}
</script>

<style scoped lang="scss">
.home {
  #banzhengtongji{
    height:300px;
  }
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

